#include <vector>
#include <iostream>
#include <algorithm>

class FixedDiffPairs {
public:
    static auto solve(std::vector<int> a, int diff) {
        long long int cnt = 0;
        std::sort(a.begin(), a.end());
        for (auto B : a) { 
            // A - B = C => A = B + C,
            // So the aim is to find such A
            auto ub = std::upper_bound(begin(a), end(a), B + diff);
            auto lb = std::lower_bound(begin(a), end(a), B + diff);
            cnt += std::distance(begin(a), ub) - std::distance(begin(a), lb);
        }
        return cnt;
    }
};

int main() {
    int n, diff;
    std::cin >> n >> diff;
    std::vector<int> a;
    a.reserve(n);
    
    for (int i = 0; i < n; i++) {
        int val;
        std::cin >> val;
        a.push_back(val);
    }
    
    std::cout << FixedDiffPairs::solve(std::move(a), diff) << std::endl;

    return 0;
}
